package com.carhome.adapter;

import java.util.List;

import com.carhome.bean.ArticleNewsInfo;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

public class ArticleFragmentHeadViewAdapter extends PagerAdapter {
	private List<ArticleNewsInfo> list;
	private Context context;
	private BitmapUtils mBitmapUtils;

	public ArticleFragmentHeadViewAdapter(Context context) {
		this.context = context;
		mBitmapUtils = new BitmapUtils(context);
	}

	public void setupData(List<ArticleNewsInfo> list) {
		this.list = list;
	}
	public void clearData()
	{
		list.clear();
	}
	public int getCount() {
		return list.size();
	}

	public boolean isViewFromObject(View view, Object object) {
		return view == (View)object;
	}

	public Object instantiateItem(ViewGroup container, int position) {
		ImageView imageView = new ImageView(context);
		System.out.println("imgurl "+ list.get(position).imgurl);
		imageView.setScaleType(ScaleType.FIT_XY);
		mBitmapUtils.display(imageView, list.get(position).imgurl);
		container.addView(imageView);
		return imageView;
	}

	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}

	private class ViewHolder {
		ImageView imageview;
	}
}
